<?php

namespace App\Http\Controllers\Guard\Shop;

use App\Http\Controllers\Common\GuardController;
use App\Models\Shop\Goods\GoodsClassify;
use Illuminate\Http\Request;

class GoodsClassifyController extends GuardController {

    public function lst(Request $request) {
        $conditions['pid'] = 0;
        $records = (new GoodsClassify())->getRecords($conditions)->with('children')->get();
        $this->handleChildren($records);
        return responseSuccess($records->toArray());
    }
    public function add(Request $request) {
        $id = $request->input('id',0);
        $name = $request->input('name');
        $pid = $request->input('pid',0);
        $records = GoodsClassify::updateOrcreate(compact('id'),compact('name','pid'));
        return responseSuccess($records->toArray());
    }

    public function detail(Request $request) {
        $ids = $request->input('id');
        return $this->getRecordByIds(GoodsClassify::class, $ids);
    }

    public function del(Request $request) {
        $ids = $request->input('id');
        return $this->delRecords(GoodsClassify::class,$ids);
    }
}
